package session

type SortSessionByActive []UserSession

func (sl SortSessionByActive) Len() int {
	return len(sl)
}

func (sl SortSessionByActive) Less(i int, j int) bool {

	if sl[i].lastActive > sl[j].lastActive+30 {
		return true
	}

	if sl[i].lastActive+30 < sl[j].lastActive {
		return false
	}

	// 两者的活动时间差异不超过30秒的，最近的登录时间靠前
	if sl[i].loginDate > sl[j].loginDate {
		return true
	} else {
		return false
	}

}

func (sl SortSessionByActive) Swap(i int, j int) {
	sl[i], sl[j] = sl[j], sl[i]
}
